var path = require('path');
var webpack = require('webpack');
var proxy = require('http-proxy-middleware');
module.exports = {
    entry: ['webpack/hot/dev-server', path.resolve(__dirname,'./app/main.js')],
    output: {
        path: path.resolve(__dirname,'./build'),
        filename: 'bundle.js',
    },
    module: {
        loaders: [
            {
                test: /\.js?$/,
                exclude: /(node_modules|bower_components)/,
                loader: 'babel-loader',
                query: {
                    presets: ['es2015', 'react']
                } //将react编译成js文件
            },
            { test: /\.css$/, loader: 'style-loader!css-loader'}, 
            //打包css文件
            { test: /\.scss$/, loader: ['style-loader','css-loader','sass-loader']}, 
            //编译sass文件
            {
                test: /\.(jpg|png|gif|ico)$/,
                loader:'url-loader?limit=8000&name=images/[name].[hash:8].[ext]'
            },
            {test:/\.(eot|ttf|woff|woff2|svg)$/,loader:'url-loader?name=fonts/[name].[ext]'}
        ]
    },
    devServer:{
        proxy:{
            '/api':{
                target:'http://api.douban.com',
                pathRewrite:{'^/api':'/'},
                changeOrigin:true
            }
        }
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin()
    ]
};